<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>编辑医生</title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"
    />
    <link rel="stylesheet" href="/public/static/css/font.css" />
    <link rel="stylesheet" href="/public/static/css/weadmin.css" />
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
      .layui-input-inline.chuansuo {
        width: 700px;
      }
    </style>
  </head>

  <body>
    <div class="weadmin-body">
      <form class="layui-form">
        <div class="layui-form-item">
          <label for="medicine-id" class="layui-form-label">
            <span class="we-red">*</span>药品id
          </label>
          <div class="layui-input-inline">
            <input
              type="text"
              value="<%- medicineinfo.id %>"
              id="medicine-id"
              name="medicine_id"
              lay-verify="required"
              disabled
              autocomplete="off"
              class="layui-input"
            />
          </div>
          <div class="layui-form-mid layui-word-aux">
            <span class="we-red">*</span>
          </div>
        </div>
        <div class="layui-form-item">
          <label for="medicine-name" class="layui-form-label">
            <span class="we-red">*</span>名称
          </label>
          <div class="layui-input-inline">
            <input
              type="text"
              value="<%- medicineinfo.name %>"
              id="medicine-name"
              name="medicine_name"
              lay-verify="required"
              autocomplete="off"
              class="layui-input"
            />
          </div>
          <div class="layui-form-mid layui-word-aux">
            <span class="we-red">*</span>
          </div>
        </div>
        <div class="layui-form-item">
          <label for="medicine-brief" class="layui-form-label">
            <span class="we-red">*</span>描述
          </label>
          <div class="layui-input-inline">
            <input
              type="text"
              value="<%- medicineinfo.brief %>"
              id="medicine-brief"
              name="medicine_brief"
              lay-verify="required"
              autocomplete="off"
              class="layui-input"
            />
          </div>
          <div class="layui-form-mid layui-word-aux">
            <span class="we-red">*</span>
          </div>
        </div>

        <div class="layui-form-item">
          <label for="pubtime" class="layui-form-label"> </label>
          <div class="layui-input-inline">
            <button class="layui-btn" lay-filter="submit" lay-submit="">
              提交
            </button>
          </div>
          <div class="layui-form-mid layui-word-aux"></div>
        </div>
      </form>
    </div>
    <script src="/public/lib/layui/layui.js" charset="utf-8"></script>
    <script
      src="/public/javascripts/wangEditor.min.js"
      charset="utf-8"
    ></script>
    <script type="text/javascript">
      layui.extend({
        admin: '{/}/public/static/js/admin',
      })
      layui.use(['form', 'layer', 'admin', 'jquery'], function () {
        var form = layui.form,
          admin = layui.admin,
          layer = layui.layer,
          $ = layui.jquery

        //监听提交
        form.on('submit(submit)', function (data) {
          //发异步，把数据提交给php
          const sendData = {
            ...data.field,
          }

          $.ajax({
            url: '/admin/doctors/medicineslist/edit',
            data: JSON.stringify(sendData),
            type: 'POST',
            // ajax 传数组对象，要改contentType 为 json
            contentType: 'application/json; charset=utf-8',
            success: function (res) {
              if (res.code === 1) {
                layer.msg(res.msg)
                console.log(res)
              } else {
                layer.alert('提交成功', { icon: 6 }, function () {
                  // 获得frame索引
                  var index = parent.layer.getFrameIndex(window.name)
                  //关闭当前frame
                  parent.layer.close(index)
                  // 将frame的上一层刷新
                  window.parent.location.reload()
                })
              }
            },
          })

          return false
        })
      })
    </script>
  </body>
</html>
